matplotlib handling colors
colormap
Matplotlib: colormap transformations — SciPy Cookbook documentation
Operating on color vectors, Operating on indices, Discrete colormap
Matplotlib: loading a colormap dynamically — SciPy Cookbook documentation
Matplotlib: show colormaps — SciPy Cookbook documentation
also "colormap has a break halfway through"
discrete colormap
code:python
import matplotlib as mpl
white center
code:python
from matplotlib.colors import ListedColormap
newcolors=[]
cmap=plt.cm.get_cmap('jet', 11)
for n in range(11):
if n==5:
else:
newcolors.append(cmap(n))
newcmap= ListedColormap(newcolors)
code:python
import matplotlib.colors as mcolors
matplotlibのcolormapのRGB情報取得と関連操作 - Qiita
Specify color beyond limits
code:python
# no value
new_cmap=cmap.set_bad(color='black', alpha=None)
# larger than limit
new_cmap=cmap.set_over(color='black', alpha=None)
# lower than limit
new_cmap=cmap.set_under(color='black', alpha=None)¶
makeing colormap from 2 RGB values
code:python
# function
def two_color(low,high,name):
import matplotlib as mpl
LinL=np.hstack((low,high))
LinL=LinL/255.
s=len(LinL)
LinL=LinL.reshape((s/3,3))
N,n3=LinL.shape
rgb=np.zeros((3,N,3))
for n in range(3):
rgbn,:,0=np.linspace(0,1,N) data=dict(zip(k,rgb)) # makes a dictionary from 2 lists
my_cmap = mpl.colors.LinearSegmentedColormap(name,data)
return my_cmap
# caling function
pylab_examples example code: custom_cmap.py
Creating a colormap from a list of colors, valying alpha, Discrete
python - Transparent colormap - Stack Overflow
MetPy Mondays `#119 - Custom Colormaps : Unidata Developer's Blog matplotlib.colors.LinearSegmentedColormap.from_list("name",list,N=)
MetPy Mondays `#158 - Custom Legends and Colormapped Lines : Unidata Developer's Blog
MetPy Mondays `#177 - Changing Figure Colors on a Skew-T : Unidata Developer's Blog
code:python
ax.set_facecolor("black")
fig.patch.set_facecolor("bisque")
2D colormaps
Pythology Blog: Designing 2D colormaps and using them with matplotlib
python - 2d hsv color space in matplotlib - Stack Overflow
A color
check available color
code:python
print(matplotlib.colors.cnames)
Examples
Changing color of bars depending on El Nino or La Nina
Colormap Examples (PyHOGS)
Colormap example for bathymetry (PyHOGS)
See also